package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * TODO
 * http://localhost:8080/supplier/list
 * @author Mr.zhao
 * @version 1.0
 * @date 2021/12/31 10:47
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    SupplierServcie supplierService;

    /**分页查询供应商
     * Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> getSupplierList(Integer page,
                                              Integer rows,
                                              String supplierName){
        return supplierService.getSupplierList(page,rows,supplierName);
    }

    /**
     * 供应商添加或修改
     * 请求URL：http://localhost:8080/supplier/save?supplierId=1
     * Supplier(
     * supplierId=null,
     * supplierName=13231, contacts=123123,
     * phoneNumber=123123, address=12312,
     * remarks=)
     */
    @PostMapping("/save")
    public ServiceVO saveOrUpdateSupplier(Supplier supplier){

        supplierService.saveOrUpdateSupplier(supplier);
        return ServiceVO.Ok();
    }

    /**
     * 删除供应商
     *
     * http://localhost:8080/supplier/delete
     */
    @PostMapping("/delete")
    public ServiceVO deleteSuppliers(String ids){


        supplierService.delete(ids);
        return ServiceVO.Ok();
    }

}
